﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Orpheus.Analyzer
{
    public class PiecewiseDefinedFunction<TValue> where TValue: class 
    {
        public PiecewiseDefinedFunction()
        {
        }

        public IList<IntervalFunction<double, TValue>> IntervalFunctions { get; protected set; }

        public TValue GetValue(double arg)
        {
            foreach(var intervalFunction in IntervalFunctions)
            {
                if (arg >= intervalFunction.Interval.Start && arg < intervalFunction.Interval.End)
                {
                    return intervalFunction.Value;
                }
            }

            return null;
        }
    }
}
